package com.eagle.roomsearch.controller.webSocketController;

import java.util.concurrent.ConcurrentHashMap;

public class WebSocketHashTable {

    public static ConcurrentHashMap<String, WebSocketController> webSocketHashTable = new ConcurrentHashMap<>();

    public synchronized static void save(String userNumber, WebSocketController webSocketController) {

        webSocketHashTable.put(userNumber, webSocketController);
    }

    public synchronized static void remove(String userNumber) {

        webSocketHashTable.remove(userNumber);
    }

    public synchronized static WebSocketController get(String userNumber) {

        return webSocketHashTable.get(userNumber);
    }

    public synchronized static boolean sendMessage(String userNumber, Message message) {
        System.out.println("WebSocketHashTable====" + userNumber);
        WebSocketController webSocketController = get(userNumber);
        if (webSocketController != null) {

            webSocketController.sendMessage(message);

            return true;
        }

        return false;
    }
}
